package demo1;

public class OverdraftState extends AccountState {
    public OverdraftState(AccountState state) {
        super(state.acc);
    }

    @Override
    public void deposit(double amount) {
        acc.setBalance(acc.getBalance() + amount);
        stateCheck();
    }

    @Override
    public void withdraw(double amount) {
        if (acc.getBalance() >= amount) {
            acc.setBalance(acc.getBalance() - amount);
            stateCheck();
        } else {
            System.out.println("余额不足，无法取款");
        }
    }

    @Override
    public void computeInterest() {
        double interest = acc.getBalance() * 0.05;
        acc.setBalance(acc.getBalance() + interest);
    }

    @Override
    public void stateCheck() {
        if (acc.getBalance() >= 0) {
            acc.setState(new NormalState(this.acc));
        }
    }
}
